<?php

namespace App\Http\Controllers\Wechat;

use EasyWeChat\Factory;
use Illuminate\Http\Request;

class ServerController{
  public function login(Request $request){
    $config = \Config::get('wechat');
    $config['official_account']['default']['oauth']['callback'] .= '?'.http_build_query($request->all());
    $app = Factory::officialAccount($config['official_account']['default']);
    $oauth = $app->oauth;
    return $oauth->redirect();
  }

  public function weixinCallback(Request $request)
  {
      $config = \Config::get('wechat');
      $app = Factory::officialAccount($config['official_account']['default']);
      $oauth = $app->oauth;
      $user = $oauth->user();
      $openid = $user->getId();
      return redirect("http://bosch.hnmuyue.com/wechat/oauth_callback?openid={$openid}");

  }
}